/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package reniec.data.access;
import java.sql.*;
/**
 *
 * @author Luis Cordova
 */
public class conexionBD {
    private Connection objConnection; // PARA LA CONEXION
    private Statement objStatement; // PARA EJECUTAR COMANDOS
    private ResultSet objResultSet; // PARA OBTENER RESULTADOS
    private PreparedStatement objPreparedStatement; // PARA TRABAJAR CON STORE PROCEDURES
    


    public conexionBD(String strDataBase, String strUserID, String strPassword) {
        AbrirConexion(strDataBase, strUserID, strPassword);
    }

    public void AbrirConexion(String strDataBase, String strUserID, String strPassword) {
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            objConnection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=" + strDataBase, strUserID, strPassword);
            if (objConnection != null) {
                System.out.println("Conexion realizada satisfactoriamente.");
            }
        } catch (Exception objException) {
            System.out.println("Error: " + objException.getMessage());
        }
    }
    
    public ResultSet getResultSet(String strSQL) {
        try {
            objStatement = objConnection.createStatement();
            objResultSet = objStatement.executeQuery(strSQL);
            return objResultSet;
        } catch (Exception objException) {
            System.out.println("Error: " + objException.getMessage());
            return null;
        }
    }    
    
}
